package com.ty.admin.controller;

import java.util.Arrays;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.ty.skysystem.entity.ContactEntity;
import com.ty.skysystem.service.ContactService;
import com.ty.common.utils.PageUtils;
import com.ty.common.utils.R;

/**
 * 车辆司机关联表: 用于连接车辆与驾驶员 字段名: truck_id => 对应表: truck 字段名: driver_id => 对应表: driver
 *
 * @author tianyuzhu
 * @email 1659770218@QQ.COM
 * @date 2020-12-11 15:52:12
 */
@RestController
@RequestMapping("contact")
public class ContactController {
  @Autowired private ContactService contactService;

  /** 列表 */
  @RequestMapping("/list")
  public R list(@RequestParam Map<String, Object> params) {
    PageUtils page = contactService.queryPage(params);

    return R.ok().put(page);
  }

  /** 信息 */
  @RequestMapping("/info/{contactId}")
  public R info(@PathVariable("contactId") Long contactId) {
    ContactEntity contact = contactService.getById(contactId);

    return R.ok().put(contact);
  }

  /** 保存 */
  @RequestMapping("/save")
  public R save(@RequestBody ContactEntity contact) {
    contactService.save(contact);

    return R.ok();
  }

  /** 修改 */
  @RequestMapping("/update")
  public R update(@RequestBody ContactEntity contact) {
    contactService.updateById(contact);

    return R.ok();
  }

  /** 删除 */
  @RequestMapping("/delete")
  public R delete(@RequestBody Long[] contactIds) {
    contactService.removeByIds(Arrays.asList(contactIds));

    return R.ok();
  }
}
